#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<queue>
using namespace std;
const int N = 1e5 + 10;
int w[N];
vector<int>e[N];
int ans[N];
int n, m;
int d[N];
void tuopu()
{
	queue<int>q;
	for (int i = 1; i <= n; i++) {
		if (!d[i]) {
			ans[i] = w[i];
			q.push(i);
		}
	}
	while (q.size()) {
		int t = q.front();
		//cout << "t==" << t << endl;
		q.pop();
		for (int v : e[t]) {
			ans[v] = max(ans[v], ans[t] + w[v]);
			if (--d[v] == 0) {
				q.push(v);
			}
		}
	}
}
int main()
{
	cin >> n;
	for (int i = 1; i <= n; i++) {
		int u;
		cin >> u;
		cin >> w[u];
		int v;
		while (cin >> v, v) {
			e[v].push_back(u);
			d[u]++;
		}
	}
	tuopu();
	int res = 0;
	for (int i = 1; i <= n; i++) {
		res = max(res, ans[i]);
	}
	cout << res << endl;
	return 0;
}